package main

import (
	"bytes"
	"fmt"
)

func main() {
	s := "abcdef"
	numRows := 3
	fmt.Println(convert(s, numRows))
}

func convert(s string, numRows int) string {
	if len(s) < numRows || numRows < 2 {
		return s
	}
	length := len(s)
	var result bytes.Buffer
	for i := 0; i < numRows; i++ {
		for j := i; j < length; j += numRows*2 - 2 {
			result.WriteByte(s[j])
			if i != 0 && i != numRows-1 {
				if mid := j + (numRows-i-1)*2; mid < length {
					fmt.Println(i, j, mid, string(s[mid]))
					result.WriteByte(s[mid])
				}
			}
		}
	}
	return result.String()
}
